package com.itsci.assignment2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EditVehicle extends Activity{
	private EditText name;
	private EditText price;
	private Button save;
	private VehicleManager veMgr;
	private String intentName;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.edit_vehicle);
		name = (EditText)findViewById(R.id.editText_edit_vehicle_name);
		price = (EditText)findViewById(R.id.editText_edit_vehicle_price);
		Intent intent = getIntent();
		intentName = intent.getStringExtra("name");
		name.setText(intent.getStringExtra("name"));
		price.setText(intent.getStringExtra("price"));
		save = (Button)findViewById(R.id.button_edit_vehicle_save);
		veMgr = new VehicleManager(EditVehicle.this, null, null, 1);
		
		save.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				VehicleBean vb = new VehicleBean(veMgr.getId(intentName),name.getText().toString(),Integer.parseInt(price.getText().toString()));
//				guideBean.setId();
//				guideBean.setGuidName();
//				guideBean.setTel();
//				guideBean.setEmail();
				veMgr.updateVehicle(vb);
				Intent gotoEdit = new Intent(EditVehicle.this,ShowVehicle.class);
				gotoEdit.putExtra("name",name.getText().toString());
				gotoEdit.putExtra("price",price.getText().toString());
				setResult(111,gotoEdit);
				finish();
				
			}
		});
		
		
	}

}
